package com.xiaobao.campusLostFoundAfter.controller;

import com.xiaobao.campusLostFoundAfter.service.TencentMapService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

// 地图API
@RestController
@RequestMapping("/map")
public class MapController {

    private static final Logger log = LoggerFactory.getLogger(MapController.class);
    private final TencentMapService mapService;

    public MapController(TencentMapService mapService) {
        this.mapService = mapService;
    }

    // 地址解析API
    @GetMapping("/geocode")
    public Map<String, Object> geocode(@RequestParam String address) throws IOException {
        Map<String, Object> geocoder = mapService.geocoder(address);
        log.info("地址解析结果：{}", geocoder);
        return geocoder;
    }

    // 逆地址解析API
    @GetMapping("/reverseGeocode")
    public Map<String, Object> reverseGeocode(@RequestParam double latitude,
                                              @RequestParam double longitude) throws IOException {
        Map<String, Object> stringObjectMap = mapService.reverseGeocoder(latitude, longitude);
        log.info("逆地址解析结果：{}", stringObjectMap);
        return stringObjectMap;
    }
}